package com.ruoyi.voucher.service.impl;

import java.util.List;
import java.util.stream.Collectors;

import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.voucher.domain.SubjectType;
import com.ruoyi.voucher.mapper.SubjectTypeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.voucher.mapper.SubjectMapper;
import com.ruoyi.voucher.domain.Subject;
import com.ruoyi.voucher.service.ISubjectService;

/**
 * 会计科目Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-02-25
 */
@Service
public class SubjectServiceImpl implements ISubjectService 
{
    @Autowired
    private SubjectMapper subjectMapper;

    @Autowired
    private SubjectTypeMapper subjectTypeMapper;

    /**
     * 查询会计科目
     * 
     * @param subjectId 会计科目主键
     * @return 会计科目
     */
    @Override
    public Subject selectSubjectBySubjectId(Long subjectId)
    {
        return subjectMapper.selectSubjectBySubjectId(subjectId);
    }

    /**
     * 查询会计科目列表
     * 
     * @param subject 会计科目
     * @return 会计科目
     */
    @Override
    public List<Subject> selectSubjectList(Subject subject)
    {
        return subjectMapper.selectSubjectList(subject);
    }

    /**
     * 新增会计科目
     * 
     * @param subject 会计科目
     * @return 结果
     */
    @Override
    public int insertSubject(Subject subject)
    {
        return subjectMapper.insert(subject);
    }

    /**
     * 修改会计科目
     * 
     * @param subject 会计科目
     * @return 结果
     */
    @Override
    public int updateSubject(Subject subject)
    {
        return subjectMapper.updateById(subject);
    }

    /**
     * 批量删除会计科目
     * 
     * @param subjectIds 需要删除的会计科目主键
     * @return 结果
     */
    @Override
    public int deleteSubjectBySubjectIds(Long[] subjectIds)
    {
        return subjectMapper.deleteSubjectBySubjectIds(subjectIds);
    }

    /**
     * 删除会计科目信息
     * 
     * @param subjectId 会计科目主键
     * @return 结果
     */
    @Override
    public int deleteSubjectBySubjectId(Long subjectId)
    {
        return subjectMapper.deleteSubjectBySubjectId(subjectId);
    }

    @Override
    public List<SubjectType> getTypeAll() {
        //倒序查询

        List<SubjectType> subjectTypes = subjectTypeMapper.selectList(null);
        //正序排列
        List<SubjectType> collect = subjectTypes.stream().sorted((o1, o2) -> o1.getTypeId().compareTo(o2.getTypeId()))
                .collect(Collectors.toList());
        return collect;
    }
}
